package com.xiaoai.httpClientTestService.httpclient.javaf;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;

public class HttpclientPost {

    public static void main(String[] args) throws Exception {
        //创建httpget对象
        CloseableHttpClient httpClient = HttpClients.createDefault();

        //创建请求对象 设置url
        HttpPost httpPost = new HttpPost("http://localhost:8080/test/getpPost");

        CloseableHttpResponse response = null;
        // 发起请求，获取response
        response = httpClient.execute(httpPost);
        // 解析
        if (response.getCode() == 200){
            String content  = EntityUtils.toString(response.getEntity(),"utf8");
            System.out.println(content);
        }
        response.close();
        httpClient.close();
    }
}
